define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'supplier.order/index',
        add_url: 'supplier.order/add',
        edit_url: 'supplier.order/edit',
        delete_url: 'supplier.order/delete',
        export_url: 'supplier.order/export',
        modify_url: 'supplier.order/modify',
        logistics_list_url: '/admin/supplier.order/logistics_list',
    };

    return {
        index: function () {
            ea.table.render({
                init: init,
                cols: [[
                    {field: 'order_sn', title: '订单编号' ,width:160},
                    {field: 'total_amount', title: '总金额', minWidth: 120 ,search:'false'
                    ,templet: function(d){
                        if (d.total_amount == null) {
                            return'￥0.00';
                        } else {
                            return '￥'+d.total_amount;
                        }
                    }},
                    {field: 'goods_images', title: '商品图', minWidth: 80, templet: ea.table.lazyimg ,search:'false'},
                    {field: 'goods_num', title: '实发商品', minWidth: 100 ,search:'false',templet: function(d){
                        return d.goods_name+' *'+(d.goods_num+d.gift_num);
                    }},
                    {field: 'goods_num', title: '商品信息', minWidth: 200 ,search:'false',templet: function(d){
                        if (d.gift_num > 0) {
                            // return d.goods_name+' *'+(d.goods_num+d.gift_num)
                            return' 商品:'+d.goods_num+' 赠品:'+d.gift_num;
                        } else {
                            // return d.goods_name+' *'+(d.goods_num+d.gift_num)
                            return' 商品:'+d.goods_num;
                        }
                    }},
                    {field: 'order_name', title: '收货人' ,hide: true},
                    {field: 'order_phone', title: '手机号' ,hide: true},
                    {field: 'order_address',title: '订单信息' ,minWidth:300 ,search:'false' ,templet: function(d){
                        return d.order_name+' '+d.order_phone+' '+d.province+''+d.city+''+d.area+''+d.order_address;
                    }},
                    {field: 'logistics_status',title: '订单状态' ,minWidth:100 ,search: 'select', selectList: {0:'待发货' ,1:'已发货' ,2:'已完成'},templet: function(d){
                        if (d.logistics_status == 0) {
                            return'待发货';
                        } else if (d.logistics_status == 1) {
                            return'已发货';
                        } else if (d.logistics_status == 2) {
                            return'已完成';
                        } else if (d.logistics_status == 9) {
                            return '已取消';
                        } else {
                            return'--';
                        } 
                    }},
                    {field: 'refund_status',title: '退款状态', search: 'select', selectList: {0: '未退款', 1: '已退款'},templet: function(d){
                        if (d.refund_status == 1) {
                            return'已退款';
                        } else {
                            return '未退款';
                        }
                    }},
                    {field: 'remark', Width: 100, title: '备注', search: 'false'},
                    {field: 'create_time', minWidth: 160, title: '创建时间', search: 'range'},
                    {
                        // fixed: 'right',
                        width: 100,
                        title: '操作',
                        templet: function(e){
                            var l ='<a class="layui-btn layuimini-btn-success layui-btn-xs" data-open="supplier.order/logistics_list?order_id='+e.id+'" data-title="订单物流信息['+e.logistics_company+']" data-full="false">物流信息</a>'
                            // var l ='<a class="layui-btn layuimini-btn-success custom-action-button" data-id="'+ e.order_batch +'" data-title="订单物流信息" data-full="false">物流信息</a>'
                            return l;  
                        }
                    },
                ]],
            });

            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
        // 订单物流列表
        logistics_list: function () {
            ea.table.render({
                // init: init,
                toolbar: [],
                defaultToolbar:[''],
                search:false,
                page: true,
                // height: 'full-400',
                url: init.logistics_list_url,
                cols: [[
                    // {field: 'company', title: '快递公司' ,width:150, search: 'false'},
                    {field: 'nu', title: '物流单号' ,width:150, search: 'false'},
                    {field: 'statusTitle', title: '物流状态' ,width:100, search: 'false'},
                    {field: 'context', minWidth: 160, title: '物流信息', search: 'false'},
                    // {field: 'create_time', minWidth: 200, title: '更新时间', search: 'range'},
                    {field: 'create_time', minWidth: 160, title: '更新时间', search: 'false'},
                ]],
            });
            ea.listen();
        }
    };
});